package cn.codeforfun.controller;

import cn.codeforfun.entity.User;
import cn.codeforfun.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Package cn.codeforfun.controller
 * Project SpringBootCache
 * Author WangBin
 * Email bin.wang12@pactera.com
 * Created on 2017/6/8 15:40
 * version 1.0.0
 */
@RestController
public class UserController {
  @Resource
  private UserService userService;

  @RequestMapping(value = "{name}", method = RequestMethod.GET)
  public User findByName(@PathVariable String name) {
    return userService.findByUsername(name);
  }

  @RequestMapping(method = RequestMethod.POST)
  public void save(@RequestBody User user) {
    userService.saveUser(user);
  }

  @RequestMapping(method = RequestMethod.GET)
  public List<User> findAll() {
    return userService.findAll();
  }
}
